package 剑指Offer._0110;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/7/6 21:45
 * 用两个栈实现队列
 * 算法：栈
 * 队列是先进先出，栈是先进后出
 * 两个栈实现队列，一个栈存数据，另一个栈读取数据
 */
public class _09 {
    class CQueue {
        Deque<Integer> store;
        Deque<Integer> read;

        public CQueue() {
            store = new LinkedList<>();
            read = new LinkedList<>();
        }

        public void appendTail(int value) {
            store.push(value);
        }

        public int deleteHead() {
            if (read.isEmpty()) while (!store.isEmpty()) read.push(store.pop());
            if (read.isEmpty()) return -1;
            else return read.pop();
        }
    }
}
